package com.cw.util;

import com.github.pagehelper.util.StringUtil;

/**
 * UTF-8(16进制)转换工具
 * @author: ly
 * @date: 2020/10/19 15:51
 **/
public class Utf8ConverStringUtil {

    /**
     * UTF-8(16进制)转换字符串
     * @param utf8Code 编码
     * @author ly
     * @date 2020/10/19 15:53
     * @return java.lang.String
     */
    public static String converString(String utf8Code) {
        if (StringUtil.isNotEmpty(utf8Code)) {
            String code = "&#x";
            if (utf8Code.contains(code)) {
                String[] strs = utf8Code.split("&#x");
                StringBuilder sb = new StringBuilder();
                int temp;
                for(int i=1; i<strs.length; i++) {
                    temp = Integer.parseInt(strs[i].substring(0,strs[i].length()-1),16);
                    sb.append((char)temp);
                }
                return sb.toString();
            }
            return utf8Code;
        }
        return null;
    }
}
